package cn.stylefeng.guns.modular.controller;

import cn.stylefeng.guns.modular.entity.Greeting;
import cn.stylefeng.guns.modular.entity.HelloMessage;
import cn.stylefeng.guns.modular.service.TranTestService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.SuccessResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.util.HtmlUtils;

/**
 * @ProjectName: guns-architecture
 * @Package: cn.stylefeng.guns.modular
 * @ClassName: TestWebSocketController
 * @Description: java类作用描述
 * @Author: 唐朝
 * @CreateDate: 2019/12/20 14:58
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/12/20 14:58
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */

@Controller
@RequestMapping("/WebSocket/")
public class TestWebSocketController extends BaseController {

    private String PREFIX = "/modular/system/dept/";


    @Autowired
    private TranTestService testMultiDbService;

    @RequestMapping("index")
    public String index() {

        return "WebSocket.html";
    }

    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage message) throws Exception {
        Thread.sleep(1000); // simulated delay
        return new Greeting("Hello, " + HtmlUtils.htmlEscape(message.getName()) + "!");
    }



    @RequestMapping("success")
    public Object testSuccess() {
        testMultiDbService.testSingleSuccess();
        return SuccessResponseData.success();
    }

    @RequestMapping("fail")
    public Object testFail() {
        testMultiDbService.testSingleFail();
        return SuccessResponseData.success();
    }
}
